<template>
  <DateTime
    v-model="dateTimeValue"
    :default-time="new Date(2025, 1, 1, 0, 0, 0)"
    :disabled-date="disabledDate"
    :disabled-hours="disabledHours"
    :disabled-minutes="disabledMinutes"
    :disabled-seconds="disabledSeconds"
    :="$attrs"
  />
  <!-- time-format="00:00:00" -->
</template>

<script setup>
const props = defineProps({
  timePointType: {
    type: String,
    default: 'start' // start | end
  },
  timeBoundary: {
    type: String,
    default: ''
  }
})

const dateTimeValue = defineModel({
  type: Boolean,
  default: false
})

onMounted(() => {
  //
})

// 将日期禁用逻辑抽取为计算属性
const isStartEndSameDay = computed(() => {
  return (
    g_dayjs(dateTimeValue).format('YYYY-MM-DD') ===
    g_dayjs(props.timeBoundary).format('YYYY-MM-DD')
  )
})

const isStartEndSameHour = computed(() => {
  return (
    g_dayjs(dateTimeValue).format('YYYY-MM-DD HH') ===
    g_dayjs(props.timeBoundary).format('YYYY-MM-DD HH')
  )
})
const isStartEndSameMinutes = computed(() => {
  return (
    g_dayjs(dateTimeValue).format('YYYY-MM-DD HH:mm') ===
    g_dayjs(props.timeBoundary).format('YYYY-MM-DD HH:mm')
  )
})
const startDisabledDate = time => {
  if (props.timeBoundary) {
    return time.getTime() > new Date(props.timeBoundary).getTime()
  }
  return false
}
const startDisabledHours = _ => {
  if (isStartEndSameDay.value) {
    const hours = g_dayjs(props.timeBoundary).hour()
    return Array.from({ length: 23 - hours }, (_, i) => hours + i + 1)
  }
  return []
}
const startDisabledMinutes = _ => {
  if (isStartEndSameHour.value) {
    const minute = g_dayjs(props.timeBoundary).minute()
    return Array.from({ length: 59 - minute }, (_, i) => minute + i + 1)
  }
  return []
}
const startDisabledSeconds = _ => {
  if (isStartEndSameMinutes.value) {
    const second = g_dayjs(props.timeBoundary).second()
    return Array.from({ length: 59 - second + 1 }, (_, i) => second + i)
  }
  return []
}
const endDisabledDate = time => {
  if (props.timeBoundary) {
    return (
      new Date(g_dayjs(time).format('YYYY-MM-DD 23:59:59')).getTime() <
      new Date(props.timeBoundary).getTime()
    )
  }
  return false
}
const endDisabledHours = _ => {
  if (isStartEndSameDay.value) {
    const hours = g_dayjs(props.timeBoundary).hour()
    return Array.from({ length: hours }, (_, i) => i)
  }
  return []
}
const endDisabledMinutes = _ => {
  if (isStartEndSameHour.value) {
    const minute = g_dayjs(props.timeBoundary).minute()
    return Array.from({ length: minute }, (_, i) => i)
  }
  return []
}
const endDisabledSeconds = _ => {
  if (isStartEndSameMinutes.value) {
    const second = g_dayjs(props.timeBoundary).second()
    return Array.from({ length: second + 1 }, (_, i) => i)
  }
  return []
}

const disabledDate = time => {
  return props.timePointType === 'start'
    ? startDisabledDate(time)
    : endDisabledDate(time)
}
const disabledHours = _ => {
  return props.timePointType === 'start'
    ? startDisabledHours()
    : endDisabledHours()
}
const disabledMinutes = _ => {
  return props.timePointType === 'start'
    ? startDisabledMinutes()
    : endDisabledMinutes()
}
const disabledSeconds = _ => {
  return props.timePointType === 'start'
    ? startDisabledSeconds()
    : endDisabledSeconds()
}
</script>

<style scoped lang="scss"></style>
